package mo.tags.stack;

import java.util.Stack;

public class LO31 {

    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> stack = new Stack<>();
        int i = 0;
        int j = 0;
        while (i < pushed.length) {
            stack.push(pushed[i]);
            i++;
            while (!stack.isEmpty() && stack.peek() == popped[j]) {
                stack.pop();
                j++;
            }
        }

        return j == popped.length;
    }

    public static void main(String[] args) {
        LO31 test = new LO31();
        System.out.println(test.validateStackSequences(new int[]{1,2,3,4,5}, new int[]{4,3,5,1,2}));
    }

}
